<script type="text/javascript">
	$(document).ready(function() {
		$('#fermerpopup').click(function() {
			window.close();
		});
	});

	/*$.ajax({
	  	type: "GET",
	  	url: "../GenererScript_ajax/<?php echo $satable['Table']['id'];?>/<?php echo $idunique;?>",
	   	error:function(msg){
	     	alert( "Error !: " + msg );
	   	},
	   	success:function(data){
	   		document.getElementById('progressbar').style.width='100%';
	   		$('#avancement').eq(0).text('100%');
   			var obj = jQuery.parseJSON(data);
			window.opener.location.href = "../EnvoyerFichier/"+obj.path+"/"+obj.filename;
			setTimeout('window.close();',2000);
			
		}
	});*/

	$.post("<?php echo $this->request->webroot;?>dynamiques/GenererScript_ajax",
	  	{ table_id: "<?php echo $satable['Table']['id'];?>", idunique: "<?php echo $idunique;?>", rupture_id: "<?php echo $rupture_id;?>" },
		function(data){
		    //alert("Data Loaded: " + data);
		    document.getElementById('progressbar').style.width='100%';
	   		$('#avancement').eq(0).text('100%');
   			var obj = jQuery.parseJSON(data);
			window.opener.location.href = "<?php echo $this->request->webroot;?>dynamiques/EnvoyerFichier/"+obj.path+"/"+obj.filename;
			setTimeout('window.close();',2000);
		}
	);


	function progressbarscutation (){
		//alert('rleb test');
		setInterval('updateprogressbar()',1500);
	}

	function updateprogressbar (){
		$.ajax({
		   	type: "GET",
		   	url: "../ProgressBar_ajax/<?php echo $idunique;?>",
		   	error:function(msg){
		   		if ($('#avancement').eq(0).text()!='100%') {
		     		alert( "Error 2!: " + msg );
		     	}
		   	},
		   	success:function(data){
		   		//alert('rleb ici la terre' + data);
	   			document.getElementById('progressbar').style.width=data+'%';

	   			if (data==0 || data<=100) {
					//progressbarscutation ();
					//alert('rleb pas fini');
					$('#avancement').eq(0).text(data+'%');
				}else{
					if (data>=100){
						//alert('rleb fini');
						//window.location.href = "../EnvoyerFichier/";
					}
				}
			}
		});
	}

	progressbarscutation();
</script>

<div class="container-fluid">
  	<div class="row-fluid">
		<div class="span12">
			<div class="navbar"/>
				<div class="navbar-inner_gpp">
					<div class="container-fluid">
						<div class="nav-collapse">
							<div class="row-fluid">
								<div class="span2">
									<p>
										<a id="fermerpopup" class="btn btn-inverse btn-small" >Fermer</a>
									</p>
								</div>
								<div class="span10">
									<p>
									</p>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="page-header">
				<label id="avancement">0%</label>
				<div class="progress progress-striped active">
				  	<div id="progressbar" class="bar" style="width: 1%;">
				   	</div>
				</div>
			</div>
		</div>
	</div>
</div>
